/*
@Copyright:LintCode
@Author:   tjyemail
@Problem:  http://www.lintcode.com/problem/space-replacement
@Language: C++
@Datetime: 16-02-09 05:18
*/
#include<bits/stdc++.h>
using namespace std;

class Solution {
public:
    /**
     * @param string: An array of Char
     * @param length: The true length of the string
     * @return: The true length of new string
     */
    int replaceBlank(char string[], int length) {
        // Write your code here
        int space=0,len;
        if (string==NULL)
            return 0;
        for(int i=0;i<length;++i)
            if (string[i]==' ')
                ++space;
        len = length + space * 2;
		cout<<"new len is "<<len<<endl; 	
		string[len--] = '\0';
        for(int i=length-1;i>=0;--i){
            if (string[i]==' '){
                string[len--] = '0';
                string[len--] = '2';
                string[len--] = '%';
            }
            else
                string[len--]=string[i];
        }
        return strlen(string);
    }
};

int main()
{
	Solution A;
	char a[9]={
		'a',' ','b',' ','c'
	};
	for(int i=0;i<sizeof(a)/sizeof(a[0]);++i)
		cout<<a[i];
	cout<<endl;
	int l=A.replaceBlank(a,5);
	cout<<l<<endl;
	for(int i=0;i<l;++i)
		cout<<a[i];
	cout<<endl;

	return 0;
}
